<?php

class Emms_Form_Admin_PerformanceDataXtraOfficer extends HTech_Form
{
    protected $_primary  = 'PerformanceDataXtraId';
    protected $_officer;
    
    private function _init($id)
    {
        $officers = new Zend_Db_Table(array(
            'name' => 'view_officers', 
            'primary' => 'OfficerUserId'));
        $this->_officer = $officers->find((int) $id)->current();
        if(!$this->_officer) throw new Exception($this->translate("Invalid officer"));
    }
    
    public function __construct($id) 
    {
        parent::__construct();
        $this->_init($id);
        
        $this->setName('PerformanceDataXtra');
        
        $this->setAttrib('title', $this->translate("Performance data"));
        $this->setDescription($this->translate("Add performance data"));
        
        $pdxId = new Zend_Form_Element_Hidden('PerformanceDataXtraId');
        
        $officerUserId = new Zend_Form_Element_Hidden('OfficerUserId');
        $officerUserId->setValue($this->_officer->OfficerUserId);
        
        $officer = new Zend_Form_Element_Text('Officer');
        $officer->setLabel("Officer")
            ->setRequired(true)
            ->setAttrib('readonly', 'true')
            ->setValue($this->_officer->FullName);
        
        $meetings = new Zend_Form_Element_Text('Meetings');
        $meetings->setLabel("Meetings")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Required field, can't be empty")))
            ->addFilter('Digits')
            ->addValidator('Int', true, array(
                    'messages' => $this->translate("Only numeric values allowed")));
        
        $clientAssistance = new Zend_Form_Element_Text('ClientAssistance');
        $clientAssistance->setLabel("Client assistance")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Required field, can't be empty")))
            ->addFilter('Digits')
            ->addValidator('Int', true, array(
                    'messages' => $this->translate("Only numeric values allowed")));
        
        $personalGrowth = new Zend_Form_Element_Text('PersonalGrowth');
        $personalGrowth->setLabel("Personal growth")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Required field, can't be empty")))
            ->addFilter('Digits')
            ->addValidator('Int', true, array(
                    'messages' => $this->translate("Only numeric values allowed")));
        
        $churchMinistry = new Zend_Form_Element_Text('ChurchMinistry');
        $churchMinistry->setLabel("Church ministry")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Required field, can't be empty")))
            ->addFilter('Digits')
            ->addValidator('Int', true, array(
                    'messages' => $this->translate("Only numeric values allowed")));
        
        $training = new Zend_Form_Element_Text('Training');
        $training->setLabel("Training")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Required field, can't be empty")))
            ->addFilter('Digits')
            ->addValidator('Int', true, array(
                    'messages' => $this->translate("Only numeric values allowed")));
        
        $submit = new Zend_Form_Element_Submit('Submit');
        $submit->setLabel("Submit")
            ->addDecorator(new HTech_Form_Decorator_Button(array('type'=>'submit')));
        
        $this->addElements(array($officer,$meetings,$clientAssistance,$personalGrowth,$churchMinistry,$training,$submit,$officerUserId,$pdxId));        
    }
}